package cn.mdx.controller;

import cn.mdx.adminservice.AdminService;
import cn.mdx.adminservice.RootService;
import cn.mdx.common.beans.ResultBean;
import cn.mdx.common.beans.User;
import cn.mdx.pojo.*;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

@SuppressWarnings({"ALL", "AlibabaClassMustHaveAuthor"})
@RestController
@Controller
@RequestMapping("/root")
@CrossOrigin
public class RootController {

    @Autowired
    public RootService rootService;

    @Autowired
    public AdminService adminService;


    @PostMapping("/statistics")
    public ResultBean getBySome(Integer cid,Integer timeClass){
        return new ResultBean( rootService.getBySome(cid,timeClass));
    }

    //分页查询专利信息
    @RequestMapping("/getAllPatent")
    public ResultBean getAllPatent(Integer cid,Integer pageno){
        System.out.println("cid:"+cid+"==========pageno:"+pageno);
        PageInfo<Patent> paten=rootService.getAll(cid,pageno);
        return new ResultBean(paten);
    }

    //分页查询平台资源信息   cid 院别     pageno 页面序号
    @RequestMapping("/getAllTerrace")
    public ResultBean getAllTerrace(Integer cid,Integer pageno){
        PageInfo<Terrace> terrace=rootService.getAllTerrace(cid,pageno);
        return new ResultBean(terrace);
    }

    /**
     *
     * @param session
     * @param cid 院别
     * @param pageno  页面序号
     * @return
     */
    @RequestMapping("/getAllTeam")
    public ResultBean getAllTeam(HttpSession session,Integer cid,Integer pageno){
        PageInfo<Team> teams=rootService.getAllTeam(session,cid,pageno);
        return new ResultBean(teams);
    }


    @RequestMapping("getAllSoftware")
    public ResultBean getAllSoftware(HttpSession session,Integer cid,Integer pageno){
        System.out.println(cid+"==pageno"+pageno);
        User user=(User)session.getAttribute("user");
        PageInfo<Software> software=rootService.getAllSoftware(cid,pageno,user.getId());
        System.out.println("数据量"+software.getSize());
        return new ResultBean(software);
    }

    /**
     * root用户查询需要传递cid
     * @param session
     * @param cid
     * @param pageno
     * @return
     */
    @RequestMapping("getAllSchool")
    public ResultBean getAllSchool(HttpSession session,Integer cid,Integer pageno){
        User user=(User)session.getAttribute("user");
        System.out.println(cid+"=========pageno:"+pageno);
        PageInfo<School> school=adminService.getAllSchool(user,cid,pageno);
        System.out.println("校企数据量："+school.getSize());
        return new ResultBean(school);
    }


    @RequestMapping("/getAllDemand")
    public ResultBean getAllDemand(HttpSession session,Integer pageno){
        User user=(User) session.getAttribute("user");
        PageInfo<Demand> demandPageInfo=adminService.getAllDemand(user,pageno);
        return new ResultBean(demandPageInfo);
    }

    @RequestMapping("/getAllNeeduser")
    public ResultBean getAllNeeduser(HttpSession session,Integer pageno){
        User user=(User)session.getAttribute("user");
        PageInfo<Needuser> needusers=adminService.getAllNeeduser(user,pageno);
        return new ResultBean(needusers);
    }


    @RequestMapping("/getAllAchievement")
    public ResultBean getAllAchievement(HttpSession session,Integer pageno){
        User user=(User)session.getAttribute("user");
        PageInfo<Achievement> achievementPageInfo=adminService.getAllAchievement(user,pageno);
        return new ResultBean(achievementPageInfo);
    }


    /**
     * 获取对接成果信息
     * @param pageno
     * @return
     */
 /*   public ResultBean getAllResult(HttpSession session,Integer pageno){
        PageInfo<Result> resultPageInfo=rootService.getAllResult(session,pageno);
        return new ResultBean(resultPageInfo);
    }
*/

    @RequestMapping("/getAllCollege")
    public ResultBean getAllCollege(){
        System.out.println("选择学院");
        List<College> collegeList=rootService.getAllCollege();
        return new ResultBean(collegeList);
    }


    /**
     * 获取对接成果信息
     * @param pageno
     * @return
     */
    @RequestMapping("/getAllResult")
    public ResultBean getAllResult(Integer pageno,Integer cid,HttpSession session){
        System.out.println(pageno+"======cid:"+cid);
        User user=(User)session.getAttribute("user");
        PageInfo<Result> resultPageInfo=adminService.getAllResultByCid(user,cid,pageno);
        System.out.println(resultPageInfo.getSize());
        return new ResultBean(resultPageInfo);
    }







}
